package com.cskaoyan.day1.generic2;

/**
 * @author Common-zhou
 * @since 2023-02-27 09:53
 */
public class Holder1Demo {
    public static void main(String[] args) {
        //testAutoCar();

        testTruck();
    }

    private static void testTruck() {
        Holder1 holder1 = new Holder1(new Truck());

        Truck truck = (Truck) holder1.get();

        truck.run();

        //ClassCastException com.cskaoyan.day1.generic2.Truck cannot be cast to com.cskaoyan.day1.generic2.AutoCar

        // 编译期异常
        AutoCar autoCar = (AutoCar) holder1.get();

        // 运行期异常
        autoCar.run();

    }

    private static void testAutoCar() {
        AutoCar autoCar = new AutoCar();
        Holder1 holder1 = new Holder1(autoCar);

        AutoCar car = (AutoCar) holder1.get();
        car.run();
    }
}
